package twt.practice.votingsystem.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import twt.practice.votingsystem.service.VoteService;
import twt.practice.votingsystem.utils.APIResponse;

@RestController
public class VoteController {

    @Autowired
    VoteService voteService;

    @GetMapping("/voterview")
    public APIResponse getVote(){
        return voteService.getVote();
    }

    @GetMapping("/voterpage")
    public APIResponse getChoice(@RequestParam("title_id") Integer title_id){
        return voteService.getChoice(title_id);
    }

    @PostMapping("/voter")
    public APIResponse Voting(@RequestParam("title_id") Integer title_id,
                                 @RequestParam("choice_id") Integer choice_id){
        return voteService.Voting(title_id,choice_id);
    }

}
